package com.example.myapplication.tack_22;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_22.adapter.AllRouteAdapter;
import com.example.myapplication.tack_22.data.AllRoutesData;
import com.example.myapplication.utils.OkHttpTool;

public class AllRoutesActivity extends AppCompatActivity {
    private ImageView exit;
    private RecyclerView route;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_22_activity_all_routes);
        init();
        getImg();
        getRout();
        exit_();
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AllRoutesActivity.this.finish();
            }
        });
    }

    private void getRout() {
        String url = "prod-api/api/metro/line/list";
        OkHttpTool.doNetRequest(url, OkHttpTool.GET, AllRoutesData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                AllRoutesData allRoutesData = (AllRoutesData)obj;
                if(allRoutesData.getCode() == 200){
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            route.setLayoutManager(new LinearLayoutManager(AllRoutesActivity.this));
                            route.setAdapter(new AllRouteAdapter(allRoutesData.getData(),AllRoutesActivity.this));
                        }
                    });

                }
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void getImg() {
        Glide.with(AllRoutesActivity.this).load(OkHttpTool.URL
        + "/prod-api/profile/upload/image/2021/05/08/554f2392-1e1c-4449-b95c-327a5f7ec91d.jpeg")
                .into(img);
    }

    private void init() {
        exit = findViewById(R.id.exit);
        route = findViewById(R.id.route);
        img = findViewById(R.id.img);
    }
}